package com.r2coding.music.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.r2coding.common.util.Result;
import com.r2coding.music.entity.SingerCommentEntity;
import com.r2coding.music.service.SingerCommentService;
import com.r2coding.music.vo.resp.SingerCommentRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:98k灬
 * @since:2022/05/30 23:01
 **/
@RestController
@RequestMapping("/api/singerComment")
public class ApiSingerCommentController {
    @Autowired
    SingerCommentService singerCommentService;

    /**
     * 发表评论
     *
     * @param comment 评论信息
     * @return 统一响应体
     */
    @PostMapping("/save")
    public Result save(@RequestBody SingerCommentEntity comment) {
        singerCommentService.saveComment(comment);
        return Result.ok();
    }

    /**
     * 根据歌手id查询该歌手所有的评论信息
     *
     * @param reqVo 请求信息
     * @return 统一响应体
     */
    @GetMapping("/getAllComment/{id}")
    public Result getAll(@PathVariable("id") Integer id) {
        List<SingerCommentRespVo> list = singerCommentService.getAll(id);
        return Result.ok(list);
    }

    /**
     * 根据歌手id查询该歌手的评论数量
     *
     * @param id 歌手id
     * @return 统一响应体
     */
    @GetMapping("/getCommentCount/{id}")
    public Result getCommentCount(@PathVariable("id") Integer id) {
        int count = singerCommentService.count(new QueryWrapper<SingerCommentEntity>().eq("singer_id", id));
        return Result.ok(count);
    }
}
